<template>
<el-card shadow="never" style="margin: 10px 0;">
  <div>
      <h2>风险报告</h2>
  </div>
  <el-form :model="form">
    <el-row :gutter="30">
      <el-col :xs="24" :sm="12" :md="8" :lg="6">
        <el-form-item label="CID:">
          <el-input v-model="form.CID" placeholder="请输入CID" />
        </el-form-item>
        <el-form-item label="风险名称:">
          <el-input v-model="form.new_poison" placeholder="请输入风险名称" />
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
  <div style="text-align: right;">
    <el-button type="primary" @click="saveData()">确定</el-button>
    <el-button @click="reset()">重置</el-button>
  </div>
</el-card>
  <!-- 新增或编辑的抽屉 -->

</template>

<script>
import sDrawer from "@/components/s-drawer/s-drawer.vue"
export default {
  components: {
    sDrawer,
  },
  watch: {
    visible(value) {
      if (!value) {
        this.form = {}
      }
    }
  },
  data() {
    return {
      form: {
        CID:"",
        new_poison:"",
      },
      visible: false,
      tableData: [],
      totalNum: 100,
      search: {
        pageNum: 1,
        pageSize: 10,
        // token: "",
      },
    };
  },
  created() {
    // this.search.token = localStorage.getItem("token");
    this.getList();
  },
  methods: {
    async getList() {
      const res = await this.$request.get(
        "/zz/",
        { params: this.search }
      );
      
      if (res.data.code === 200) {
        // this.tableData = res.data.data.sort((a, b)      
        console.log(res.data)
        this.tableData = res.data.data;
        this.totalNum = res.data.zs
      }
    },
    // 每页条数改变时触发 选择一页显示多少行
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.search.pageSize = val;
      this.getList();
    },
    // 当前页改变时触发 跳转其他页
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.search.pageNum = val;
      this.getList();
    },
    reset() {
        this.form =
            {
              CID:"",
              new_poison: "",
            };
      },
    editItem(row) {
      this.form = this.$deepClone(row)
      this.visible = true
    },

    async saveData() {
          // const formData = new FormData();
          // for (const key in this.form) {
          //   if (key === 'file' && this.form.file) {
          //     formData.append(key, this.form.file,this.form.file.name);
          //   } else {
          //     formData.append(key, this.form[key]);
          //   }
          // }
          const res = await this.$request.post('/admin/poison/set/', this.form,{
             headers: {
              'Content-Type': 'multipart/form-data'
            }
          })
          if (res.data.code === 200) {
              this.$message.success(res.data.message)
              this.getList()
              this.visibleAdd = false

             // 在成功保存数据后自动刷新页面
              location.reload();
            }
    },


    // 照片文件超出个数限制时的钩子
    handleExceed(files, fileList) {
      this.$notify.warning({
      title: '警告',
      message: `只能选择 ${this.limitNum} 个文件，当前共选择了 ${files.length + fileList.length} 个`
      })
    },
    // 上传照片文件之前的钩子
    handleBeforeUpload(file) {
      const size = file.size / 1024 / 1024
          if (size > 1) {
            this.$notify.warning({
            title: '警告',
            message: '图片大小必须小于1M'
          })
      }
    },
    handleSuccess1(res) {
        console.log(res.data,'777777777777777777777777777777777777777')
        this.form.img_url = res.data.file
        this.dialogImageUrl = ''
        this.$notify({
            title: '通知',
            message: '上传文件成功~',
            type: 'success',
            duration: 5000
      })
    },



  },
};
</script>

<style scoped>
.el-pagination {
  margin-top: 10px;
}

.el-row {
  margin-bottom: 20px;
}

.el-row:last-child {
  margin-bottom: 0px;
}
</style>